package com.dmgis.qxfw.dataservice.gisservice.service.Impl;

import com.dmgis.entity.DmMapPoint;

import com.dmgis.qxfw.dataservice.gisservice.service.Transform;
import com.dmgis.weblib.MapProj;
import com.dmgis.weblib.MapProjPara;
import org.springframework.stereotype.Service;

@Service("Transform")
public class TransformImpl implements Transform {

    //兰伯特转换到经纬度
    static MapProj _ProLbtoGeo = null;
    //经纬度转换到兰伯特
    static MapProj _ProGeotoLb = null;
    //墨卡托转换到经纬度
    static MapProj _ProMkttoGeo = null;
    //经纬度转换到墨卡托
    static MapProj _ProGeotoMkt = null;

    public DmMapPoint LonLatConvertToLambert1(Double x, Double y){

        if(_ProGeotoLb == null){
            MapProjPara oldmpara = new MapProjPara();
            oldmpara.setpProjType((short) 1);
            oldmpara.setpEarthParam((short)12);
            MapProjPara newmpara = new MapProjPara();
            newmpara.setpProjType((short)4);
            newmpara.setpEarthParam((short)1);
            newmpara.setpLon(110);
            newmpara.setPlat(30);
            newmpara.setPlat1(30);
            newmpara.setPlat2(60);
            _ProGeotoLb = new MapProj(oldmpara,newmpara);
        }

        double[] xy = _ProGeotoLb.Convxy(x,y);
        if(xy.length==2)
            return new DmMapPoint(xy[0],xy[1]);
        return null;
    }

    public DmMapPoint LambertConvertToLonLat1(Double x, Double y){
        if(_ProLbtoGeo == null){
            MapProjPara paraold = new MapProjPara();
            MapProjPara paranew = new MapProjPara();
            paraold.setpProjType((short) 4);
            paraold.setpEarthParam((short) 1);
            paraold.setpLon(110);
            paraold.setPlat(30);
            paraold.setPlat1(30);
            paraold.setPlat2(60);
            paranew.setpProjType((short) 1);
            paranew.setpEarthParam((short) 12);
            _ProLbtoGeo = new MapProj(paraold,paranew);
        }
        double[] xy = _ProLbtoGeo.Convxy(x,y);
        if(xy.length==2)
            return new DmMapPoint(xy[0],xy[1]);
        return null;
    }
}
